#!/bin/sh
#
# Things that need to be done every night or so
#
cd /home/counter/counter
. tools/runscript

date
# Report some stats at the beginning, for watching.
tools/automachcount

# Do maintenance work.
echo "Check some email addresses"
checkafew 500

date
echo "Check some persons' places"
cleansome --random --watch placeid --limit 100 persons
date
echo "Send out some reminders mails"
remindermail 2000 | tee logs/lastmailsent | sh
echo -n "Reminders sent: "
wc -l logs/lastmailsent

# no longer required....
#date
#echo "Check some machines"
#(cd machines; ./matchtoregistered --count 5000 --days 3)

date
echo "Freeze some old entries"
freezeoldfolks --count 200
# the typical day has 50-100 entries needing to freeze. 200 allows the
# counter to catch up after the downtime.
echo "Freeze some recently old entries"
freezefolks --days 2
# note -- the limit is practically useless now, due to a large number
# of junk entries. But I want to fix the junk entries. - HTA -
date
echo "Email some recently frozen entries"
emailtofrozen --limit 400 --agecheck

date
# a miserable patch for a failure of error handling....
# locks are sometimes left dangling by the email register script
ls -l /home/counter/email/mailerdir
rm -f /home/counter/email/mailerdir/count.LOCK
rm -f /home/counter/email/mailerdir/countmach.LOCK*
#
# Cleaning up after the autogeneration of tempplots
echo "Remove temp plots"
find www/tempplots/ -name '*.png' -type f -mtime +0 | wc -l
find www/tempplots/ -name '*.png' -type f -mtime +0 -exec rm -f \{} \;
date
